import { defineStore } from 'pinia'
import { ItagRoute } from '@interface/tag'

export const useTagStore = defineStore('tagId', {
  state: (): {
    viewTags: ItagRoute[]
  } => {
    return {
      viewTags: [],
    }
  },
  getters: {},
  actions: {
    // 添加tag
    pushViewTags(route: ItagRoute) {
      let target = this.viewTags.find((item) => item.path == route.path) as ItagRoute
      if(!target) {
        this.viewTags.push(route)
      }
    },
    // 删除tag
    removeViewTags(route: ItagRoute) {
      this.viewTags = this.viewTags.filter((item) => item.path != route.path)
    }

  },
  persist: {
    enabled: true, //开启数据缓存
    strategies: [
      {
        storage: localStorage, //默认走session
        paths: ['viewTags'],
      },
    ],
  },
})
